package com.unicampmaps;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class SearchView extends LinearLayout {
	
	private Button btnSettings;
	private EditText edtSearch;
	
	@SuppressLint("NewApi")
	public SearchView(Context context,AttributeSet set){
		super(context,set);
		//this.setLayoutDirection(LinearLayout.HORIZONTAL);
		btnSettings = new Button(context);
		
		btnSettings.setText("Settings");
		this.addView(btnSettings);
		
		edtSearch = new EditText(context);
		this.addView(edtSearch);
		
		edtSearch.setTextColor(Color.WHITE);
		edtSearch.setBackgroundColor(Color.GRAY);
		edtSearch.setSingleLine(true);
		
		edtSearch.setOnKeyListener(new View.OnKeyListener() {
			
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if ( event.getAction() == KeyEvent.ACTION_DOWN && 
						keyCode==KeyEvent.KEYCODE_ENTER){
					//Teremos que criar uma nova activity aqui
					//Por enquanto deixar pra la o autocomplete
					Log.i("SearchView","Enter clicado");
					Intent intent = new Intent(SearchView.this.getContext(),ListActivity.class);
					intent.putExtra("search_data", edtSearch.getText().toString());
					
					SearchView.this.getContext().startActivity(intent);
				}
				
				return false;
			}
		});
	}

}
